package cn.service.impl;

import cn.mapper.HealthTabooMapper;
import cn.pojo.HealthTaboo;
import cn.pojo.dto.VaccineTaboo;
import cn.service.HealthTabooService;
import cn.utils.LoggerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HealthTabooServiceImpl implements HealthTabooService {
    @Autowired
    private HealthTabooMapper taboo;
    @Override
    public Map<String, Object> selectTaboo(String vaccineName) {
        Map<String, Object> res = new HashMap<>();
        try {
            List<VaccineTaboo> result = this.taboo.selectTaboo(vaccineName);
            if (result.size() > 0) {
                res.put("msg", result);
            } else {
                res.put("msg", false);
            }
            LoggerUtils.info("用户信息" + result);
        } catch (Exception e) {
            e.printStackTrace();
            res.put("msg", false);
        }

        return res;
    }

    @Override
    public Map<String, Object> updateTaboo(HealthTaboo taboo) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            ok = this.taboo.updateTaboo(taboo) == 1;
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> saveTaboo(HealthTaboo taboo) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            ok = this.taboo.saveTaboo(taboo) == 1;
        }catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }
}
